import uniqueId from '@form-create/utils/lib/unique';
import {localeProps, makeRequiredRule} from '../../utils';

const label = '开关';
const name = 'jd-switch';

export default {
    icon: 'icon-switch',
    label,
    name,
    rule({t}) {
        return {
            type: 'switch',
            field: 'KG',
            title: '开关',
            info: '',
            $required: false,
            validate: false,
            props: {},
        };
    },
    watch: {
        'useScript': function(val){
            if (val.value.isScript){
                val.rule.inject = true;
                val.rule.on = val.value._script;
            } else{
                val.rule.inject = false;
                val.rule.on = {};
            }
        },
    },
    props(_, {t}) {
        return localeProps(t, name + '.props', [makeRequiredRule(),
            {
                type: 'row',
                props: {gutter: 5},
                children: [
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'switch',field: 'disabled',title: '是否禁用'}
                        ]
                    },
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input',field: 'width',title: '宽度(px)'}
                        ]
                    }
                ]
            },
            {
                type: 'row',
                props: {gutter: 5},
                children: [
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input', field: 'activeText', title: '打开时文字描述'}
                        ]
                    },
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input',field: 'inactiveText',title: '关闭时文字描述'}
                        ]
                    }
                ]
            },
            {
                type: 'row',
                props: {gutter: 5},
                children: [
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input', field: 'activeValue', title: '打开时的值'}
                        ]
                    },
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input', field: 'inactiveValue', title: '关闭时的值'}
                        ]
                    }
                ]
            },
            {
                type: 'row',
                props: {gutter: 5},
                children: [
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input', field: 'activeColor', title: '打开时背景色'}
                        ]
                    },
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'input', field: 'inactiveColor', title: '关闭时背景色'}
                        ]
                    }
                ]
            },
            {type: 'ItemScript', field: 'useScript', value: ''},
        ]);
    }
};
